package chinaums.plugin.quartz;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

import chinaums.common.util.FTPUtil;
import chinaums.entity.InsertInfo;
import chinaums.entity.ResultInsertInfo;
import chinaums.service.InsertInfoService;
import chinaums.web.controller.ReadFtpController;

@Component
public class SaveFtpData {
	
	@Resource(name = "insertInfoService")
	private InsertInfoService insertInfoService;
	
//	@Autowired
//	private   ReadFtpController  readFtpController;

	
	 //  */5 * * * * ?    每隔五秒钟更新一次   
	//  0 0 2 * * ?   每天凌晨两点更新一次
	 /**
     * 每天凌晨两点执行一次
     */
	@Scheduled(cron = "0 0 2 * * ? ")
	  public  void  insert(){
	
		
		FTPUtil fu = new FTPUtil();
		String data = fu.readConfigFileForFTP("ysq", "ysq320925", "/FTP下载",
				"172.16.36.184", 2121, "ysq.json");
		ResultInsertInfo resultInsertInfo = JSONObject.parseObject(data,
				ResultInsertInfo.class);
		for (InsertInfo insertInfo : resultInsertInfo.getListInsertInfo()) {
			// System.out.println(insertInfo);
			insertInfoService.insertInfoForFtp(insertInfo);
		}
		
//		readFtpController.insertData1();
			  System.out.println("任务正在进行中。。。。。。");
	  }
}
